package ExtendsTest;
/*
toString方法重写
 */
public class ExtendsOverrideTest2 {
    public static void main(String[] args){
        MyDate m1 = new MyDate(2022,10,1);
        System.out.println(m1);  //自动调用toString方法
        //如果没有重写toString方法，将会打印m1的哈希值
    }
}
class MyDate{
    private int year;
    private int month;
    private int day;
    public MyDate(){

    }
    public MyDate(int year,int month,int day){
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }
    //从Object继承的toString方法无法满足业务需求，需要进行重写
    public String toString(){
        return this.year+"-"+this.month+"-"+this.day;
    }
}
